/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cr.ac.una.sive.managed;

import cr.ac.una.sive.entidad.Color;
import cr.ac.una.sive.entidad.Marca;
import cr.ac.una.sive.entidad.Modelo;
import cr.ac.una.sive.entidad.Vehiculo;
import cr.ac.una.sive.entidadLocal.UsuarioLocal;
import cr.ac.una.sive.entidadLocal.VehiculoLocal;
import cr.ac.una.sive.sessionbean.VehiculoFacade;
import cr.ac.una.sive.sessionbean.VehiculoFacadeLocal;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author claribel
 */
@ManagedBean
@SessionScoped
public class VehiculoFacadeManaged {
    @EJB(mappedName = "ejb/VehiculoFacade")
    private VehiculoFacadeLocal vehiculoFacade;

    
    private ArrayList<VehiculoLocal> listaVehiculos = null;   
//    public VehiculoFacadeManaged(VehiculoFacadeLocal vehiculoFacade) {
//        this.vehiculoFacade = vehiculoFacade;
//    }

    public VehiculoFacadeManaged() {
       
    }

   
    private VehiculoLocal vehiculoLocal = new VehiculoLocal();

    public VehiculoLocal getVehiculoLocal() {
        return vehiculoLocal;
    }

    public void setVehiculoLocal(VehiculoLocal vehiculoLocal) {
        this.vehiculoLocal = vehiculoLocal;
    }

    
    public Vehiculo obtenerVehiculo(){
//        BigDecimal bd = new BigDecimal(1);
//        vehiculoLocal.setIdVehiculo(1);
       
        Vehiculo v = new Vehiculo();
        //v.setIdVehiculo(2);
        v.setPlaca(vehiculoLocal.getPlaca());
        v.setMarca(vehiculoLocal.getMarca());
        v.setColor(vehiculoLocal.getColor());
        v.setModelo(vehiculoLocal.getModelo());
        v.setAnoFabricacion(vehiculoLocal.getAnoFabricacion());
        v.setCedulaPropietario(vehiculoLocal.getCedulaPropietario());
        v.setNombrePropietario(vehiculoLocal.getNombrePropietario());
        v.setApellidoPropietario(vehiculoLocal.getApellidoPropietario());
        //setVehiculoLocal(v);
        //vehiculoFacade.create(v);
        return v;
    }
    
    public List getListaVehiculos() {
//       listaMarchamos = null;
        if (listaVehiculos == null) { 
            ArrayList listaMarchamos2 = new ArrayList(vehiculoFacade.findAll());// consultaCedula(this.usuarioLocal.getCedula());
            
        listaVehiculos = new ArrayList(); 
        Vehiculo vehiculo; 
        for (int i = 0; i < listaMarchamos2.size(); i++) { 
            vehiculo = (Vehiculo) listaMarchamos2.get(i); 
        listaVehiculos.add(new VehiculoLocal(vehiculo)); 
        } 
        
        } //sort(); 
        return listaVehiculos;
        
    }
    
    
    /**
     * Creates a new instance of VehiculoFacadeManaged
     */
    
}
